<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="btn">按钮</button>
    <div id="xz">aaa</div>
    <script>
        // 打印整个网页 window.print()
        const btn = document.getElementById('btn');
        btn.onclick = function () {
            var newWin = window.open('printer', '', '');
            var xiaozhi = document.getElementById("xz").innerText;   // 这里的id是要打印的标签里的id
            newWin.document.write(xiaozhi);
            newWin.document.location.reload();
            newWin.print();
            newWin.close();
        }
    </script>
</body>

</html>